#coding:utf-8
import httplib
import json
import sys
from jsonschema import validate
from urllib import urlencode
import requests
import logging
import util


class HttpTest(object):

    def __init__(self, domian):
        self.domian = domian
        self.session = self.create_session()

    def create_session(self):
        session = requests.session()
        return session

    def get_request(self, uri, headers=None, params=None,allow_redirects=True, timeout=None):
        resp = self.session.get(self.split_url(uri), headers=headers, params=params,
                                allow_redirects=allow_redirects, timeout=timeout)
        return resp

    def post_request(self, uri, headers=None, data=None, json=None, allow_redirects=True, timeout=None):
        resp = self.session.post(self.split_url(uri), headers=headers, data=data, json=json,
                                allow_redirects=allow_redirects, timeout=timeout)
        return resp

    def split_url(self, uri):
        return str(self.domian)+str(uri)

    def set_url(self, domian):
        self.domian = domian




if __name__ == '__main__':
    s = HttpTest('http://nbh-qa.xinyunlian.cn')
    testheaders = {'Content-Type': 'application/json'}
    testdata = {"key":"0.7915141126790437","captcha":"","password":"e10adc3949ba59abbe56e057f20f883e","loginId":"admin"}
    resp2 = s.post_request('/b2b2c-admin/web/login/authc', json=testdata)

    resp3 = s.get_request('/b2b2c-admin/web/delivery/qrCode/5069')
    with open('C:\\img\\5069.png','wb') as f:
        f.write(resp3.content)



